/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import controller.ProfissionalController;
import exception.DuplicateConstraintException;
import exception.RemoveConstraintException;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;
import javax.inject.Named;
import model.entidades.Profissional;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.Conversation;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationScoped;

/**
 *
 * @author helton
 */
@Named
@ConversationScoped
public class ProfissionalView implements View, Serializable {

    @Inject
    ProfissionalController controller;
    @Inject
    Conversation conversation;
    private Profissional profissional;
    private List<Profissional> profissionais;

    @Override
    @PostConstruct
    public void init() {
        profissional = new Profissional();
    }

    @Override
    public void closeConversation(ActionEvent event) {
        conversation.close();
    }

    @Override
    public String actionNovo() {
        throw new UnsupportedOperationException("Not supported yet.");
        //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String actionSalvar() throws DuplicateConstraintException {
        throw new UnsupportedOperationException("Not supported yet.");
        //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String actionListar() {
        return "listarProfissionais";
    }

    @Override
    public void actionRemover() throws RemoveConstraintException {
        controller.remove(profissional);
        profissionais = null;
    }

    public Profissional getProfissional() {
        return profissional;
    }

    public void setProfissional(Profissional profissional) {
        this.profissional = profissional;
    }

    public List<Profissional> getProfissionais() {
        if (profissionais == null) {
            profissionais = controller.getAll();
        }
        return profissionais;
    }

    public void setProfissionais(List<Profissional> profissionais) {
        this.profissionais = profissionais;
    }
}
